package com.gc.cscott.verify.common;

import com.gc.cscott.verify.JavaTaskOutputVerifier;
import com.gc.cscott.verify.OutputVerifier.VerifiedOutput;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import java.util.Arrays;
import org.apache.commons.lang.StringUtils;

/**
 *
 * @author root
 */
public class EqualsIgnoreCaseVerifier implements JavaTaskOutputVerifier {

    public VerifiedOutput verify(String inputText, String outputText, String validationHintText) {
        Preconditions.checkNotNull(inputText);
        Preconditions.checkNotNull(outputText);
        Preconditions.checkNotNull(validationHintText);

        String source = cleanUp(outputText.toLowerCase().trim());
        String target = cleanUp(validationHintText.toLowerCase().trim());

        if (source.equals(target)==true){
            return VerifiedOutput.outputIsCorrect();
        } else {
            return VerifiedOutput.outputIsWrong("Passed '"+source+"' but expected '"+target+"'");
        }
    }

    private String cleanUp(String text){
        return Joiner.on(" ").join(Arrays.asList(StringUtils.split(text)));
    }

}
